<?php include "../public/header.php";?>
<?php include "../public/header_edit.php";?>
<link rel="stylesheet" type="text/css" href="/static/component/laytp/module/cityPicker/city-picker.css">
<body id="optPage">
<form class="layui-form layui-form-pane" id="commentForm">
    <div class="page-title"><div class="page-title-con"><span>新建进度月报</span><div class="move_title"></div><?php include "../public/sub.php";?></div></div>
    <div class="main-container">
        <div class="block-generic">
            <div class="layui-form-item">
                <div class="layui-row layui-col-space10">
                    <div class="edittits"><span>基本信息</span></div>
                </div>
            </div>

            <div class="layui-form-item">
                <div class="layui-row layui-col-space10">
                    <div class="layui-col-md6">
                        <label class="layui-form-label">项目名称</label>
                        <div class="layui-input-block">
                            <input type="text" id="enginname" readonly placeholder="请输入" autocomplete="off" class="layui-input readonly">
                        </div>
                    </div>
                    <div class="layui-col-md6">
                        <label class="layui-form-label">施工合同金额(元)</label>
                        <div class="layui-input-block">
                            <input type="text" id="hemoney" readonly placeholder="请输入" autocomplete="off" class="layui-input readonly">
                        </div>
                    </div>
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-row layui-col-space10">
                    <div class="layui-col-md6">
                        <label class="layui-form-label">开累完成产值(元)</label>
                        <div class="layui-input-block">
                            <input type="text" id="chanfee_qian" readonly placeholder="请输入" autocomplete="off" class="layui-input readonly">
                        </div>
                    </div>
                    <div class="layui-col-md6">
                        <label class="layui-form-label">开累完成比例(%)</label>
                        <div class="layui-input-block">
                            <input type="text" id="chanrate_qian" readonly placeholder="请输入" autocomplete="off" class="layui-input readonly">
                        </div>
                    </div>
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-row layui-col-space10">
                    <div class="layui-col-md6">
                        <label class="layui-form-label"><text>*</text>填报月份</label>
                        <div class="layui-input-block">
                            <input type="text" name="month" id="month" readonly placeholder="请选择" clearable  autocomplete="off" class="layui-input bdate_ym_cus">
                        </div>
                    </div>
                    <div class="layui-col-md6">
                        <label class="layui-form-label">填报标题</label>
                        <div class="layui-input-block">
                            <input type="text" id="title" name="title" readonly placeholder="请输入" autocomplete="off" class="layui-input readonly">
                        </div>
                    </div>
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-row layui-col-space10">
                    <div class="layui-col-md12">
                        <label class="layui-form-label"><text>*</text>本月完成产值(元)</label>
                        <div class="layui-input-block">
                            <input type="text" name="chanfee" id="chanfee" placeholder="请输入" autocomplete="off" class="layui-input moneyinput">
                        </div>
                    </div>
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-row layui-col-space10">
                    <div class="layui-col-md6">
                        <label class="layui-form-label">累计完成产值(元)</label>
                        <div class="layui-input-block">
                            <input type="text" id="chanfee_lei" readonly placeholder="请输入" autocomplete="off" class="layui-input readonly">
                        </div>
                    </div>
                    <div class="layui-col-md6">
                        <label class="layui-form-label">累计完成比例(%)</label>
                        <div class="layui-input-block">
                            <input type="text" id="chanrate_lei" readonly placeholder="请输入" autocomplete="off" class="layui-input readonly">
                        </div>
                    </div>
                </div>
            </div>
            <div class="layui-form-item height_auto">
                <div class="layui-row layui-col-space10">
                    <div class="layui-col-md12">
                        <label class="layui-form-label label_textarea">备注</label>
                        <div class="layui-input-block">
                            <textarea id="explain" name="explain" placeholder="请输入" class="layui-textarea"></textarea>
                        </div>
                    </div>
                </div>
            </div>
            <?php include '../public/upinfo.php'?>
        </div>
    </div>
</form>
<script>
    var param_enginid = getQueryVariable('enginid') || 0;
    var param_dt = getQueryVariable('dt') || '';
    $("#commentForm").validate({
        rules: {
            month: {required: true},
            chanfee: {required: true},
        },
        messages:{
            month: {required: "请选择"},
            chanfee: {required: "请输入"},
        }
    });


    layui.use(['laytp', 'form'], function() {
        var form = layui.form, layer = layui.layer;
        render_input_attr();

        $('.bdate_ym_cus').datetimepicker({
            language: 'zh-CN',//显示中文
            format: 'yyyy-mm',//显示格式
            startView: '3',
            minView: "3",//设置只显示到月份
            initialDate: new Date(),//初始化当前日期
            autoclose: true,//选中自动关闭
            todayBtn: true//显示今日按钮
        }).on('changeDate',function (e) {
            var month = $("#month").val();
            $("#title").val('进度月报('+month+')')
        });


        facade.ajax({type: 'get', url: ask_engin_yue_add, data:{enginid:param_enginid,dt:param_dt}}).done(function(res){
            if (res.code === 2000) {
                var data = res.data;

                $("#enginname").val(data.enginname);
                $("#hemoney").val(data.hemoney);
                $("#chanfee_qian").val(data.chanfee_qian);
                $("#chanrate_qian").val(data.chanrate_qian);

                public_upload_file_load('upload_files');
                render_date();
                render_from();
                initParseMoney();
            }
        });




        form.on('submit(add)', function(data){
            var validRes = $("#commentForm").valid();
            if(!validRes){return false;}

            data = parseMoney(data);
            data.field.enginid = param_enginid;
            data.field.files = public_upload_file_value('upload_files');
            facade.ajax({url: ask_engin_yue_add, data:data.field}).done(function(res){
                if (res.code === 2000) {
                    dataPostTimeOut();
                }
            });
            return false;
        });

    });


    $("#chanfee").on('input propertychange',function () {
        var hemoney = parseValidNum($("#hemoney").val()) || 0;
        var chanfee_qian = parseValidNum($("#chanfee_qian").val()) || 0;
        var chanfee = parseValidNum($("#chanfee").val()) || 0;

        var chanfee_lei = parseFloat(chanfee_qian) + parseFloat(chanfee)
        $("#chanfee_lei").val(parseFormatNum(chanfee_lei,2));

        var chanrate_lei = 0;
        if(hemoney != 0){
            chanrate_lei = parseFloat(chanfee_lei) / parseFloat(hemoney) * 100;
        }
        $("#chanrate_lei").val(parseFormatNum(chanrate_lei,2));
    });



</script>
</body>
</html>
